import static org.junit.Assert.*;

import org.junit.*;



public class RPNCalculatorShould {

	private RPNCalculator calc;
	
	@Before
	public void setUp()
	{
		MathOperatorFactory factory = new BasicMathOperatorFactory();
		calc = new RPNCalculator(factory);
	}

	@Test
	public void have0InItsAccumulatorWhenCreated()
	{
		assertEquals(0.0, calc.getAccumulator(), 0.001);
	}
	
	@Test
	public void beAbleToHaveItsAccumulatorSet(){
		calc.setAccumulator(5.0);
		assertEquals(5.0, calc.getAccumulator(), 0.001);
	}
	
	@Test
	public void useAStackForHoldingOperands()
	{
		calc.setAccumulator(23);
		calc.enter();
		calc.setAccumulator(5);
		calc.enter();
		calc.setAccumulator(4);
		calc.enter();
		calc.setAccumulator(3);
		assertEquals(3.0, calc.getAccumulator(), 0.001);
		calc.drop();
		assertEquals(4.0, calc.getAccumulator(), 0.001);
		calc.drop();
		assertEquals(5.0, calc.getAccumulator(), 0.001);
		calc.drop();
		assertEquals(23.0, calc.getAccumulator(), 0.001);
		calc.drop();
		assertEquals(0, calc.getAccumulator(), 0.001);
	}
	
	@Test
	public void addTwoNumbers()
	{
		calc.setAccumulator(2);
		calc.enter();
		calc.setAccumulator(3);
		calc.execute("+");
		assertEquals(5.0, calc.getAccumulator(), 0.001);
	}
	
	@Test
	public void addThreeNumbers()
	{
		calc.setAccumulator(2);
		calc.enter();
		calc.setAccumulator(3);
		calc.enter();
		calc.setAccumulator(4);
		calc.execute("+");
		calc.execute("+");
		assertEquals(9.0, calc.getAccumulator(), 0.001);
	}
	
	@Test
	public void subtractTwoNumbers()
	{
		calc.setAccumulator(2);
		calc.enter();
		calc.setAccumulator(3);
		calc.execute("-");
		assertEquals(-1.0, calc.getAccumulator(), 0.001);
	}
	
	@Test
	public void doSin()
	{
		calc.setAccumulator(30);
		calc.execute("sin");
		assertEquals(0.5, calc.getAccumulator(), 0.001);
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void throwForIllegalOperatorStrings()
	{
		calc.execute("unknown operator string");
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
